﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace canyinguanlixitong
{
    public partial class frmqw1xiugai : Form
    {
        public frmqw1xiugai()
        {
            InitializeComponent();
        }

        string str = "Data Source=.;Initial Catalog=Supermarket management system;Integrated Security=True";

        private void frmqw1xiugai_Load(object sender, EventArgs e)
        {
            add();
            xiala();
            cbodengji.SelectedIndex = 0;
        }

        public void xiala() {
            SqlConnection conn = new SqlConnection(str);
            try
            {
                DataSet ds = new DataSet("Student");
                string sql = "select * from dbo.VIPtype";
                SqlDataAdapter asdf = new SqlDataAdapter(sql, conn);
                asdf.Fill(ds, "Student");
                this.cbodengji.DataSource = ds.Tables["Student"];
                this.cbodengji.ValueMember = "vipLeiHao";
                this.cbodengji.DisplayMember = "vipLeiName";
                DataRow row = ds.Tables["Student"].NewRow();
                row["vipLeiHao"] = -1;
                row["vipLeiName"] = "全部";
                ds.Tables["Student"].Rows.InsertAt(row, 0);
            }
            catch (Exception ex)
            {
                
              MessageBox.Show(ex.Message);
            }

        }
        public int stu;
        //传值
        public void add() {
            SqlConnection conn = new SqlConnection(str);
            conn.Open();
           
            string sql = @"select  vipLei,vipID,vipLeiName,vipName,vipSex,vipMorey,vipDip,vipQi from dbo.VIPtype,dbo.VIPuser
where dbo.VIPtype.vipLeiHao=dbo.VIPuser.vipLei and vipID='" + stu + "'";
            SqlCommand comm = new SqlCommand(sql,conn);
            SqlDataReader reader = comm.ExecuteReader();
        if(reader.Read()){
            txtstu.Text = reader["vipLei"].ToString();
            txtname.Text = reader["vipName"].ToString();
            txtphone.Text = reader["vipDip"].ToString();
            txtmone.Text = reader["vipMorey"].ToString();
            txtqi.Text = reader["vipQi"].ToString();
            txtpass.Text = reader["vipID"].ToString();
          //  cbodengji.SelectedIndex =Convert.ToInt32( reader["vipLeiName"]);
        }
        
        }

        //修改
        public void xiugai() {
            SqlConnection conn = new SqlConnection(str);
            conn.Open();
            int bianhao = Convert.ToInt32(this.txtstu.Text);
            string name = this.txtname.Text;
            string sex = "";
            if (radioButton1.Checked)
            {
                sex = "男";

            }
            else
            {
                sex = "女";
            }
            double mone = Convert.ToDouble(this.txtmone.Text);
            string phone = this.txtphone.Text;
            int i = Convert.ToInt32(this.cbodengji.SelectedIndex.ToString());
            int pass = Convert.ToInt32(this.txtpass.Text);
            string qw = this.txtqi.Text;
            try
            {
                string sql = "update dbo.VIPuser set vipName='" + name + "',vipLei='" + i + "',vipMorey='" + mone + "',vipDip='" + phone + "',vipQi='" + qw + "',vipSex='" + sex + "',vipPwd='" + pass + "' where vipID='" + stu + "' ";
                SqlCommand comm = new SqlCommand(sql, conn);
                int aa = comm.ExecuteNonQuery();
                if (aa > 0)
                {
                    MessageBox.Show("修改成功");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally {
                conn.Close();
            }
        
        
        
        
        
        
        
        
        }

        private void button1_Click(object sender, EventArgs e)
        {
            xiugai();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }



    }
}
